package cn.ljh.com.user.service.impl;

import cn.ljh.com.user.dao.UserDao;
import cn.ljh.com.user.entity.User;
import cn.ljh.com.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @author 邓立川
 * @date 2021/1/15 15:07
 * @desc 添加当前类的描述信息
 */
@Service
public class UserServiceIml implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public User findById(Long id) throws Exception {
        Optional<User> byId = userDao.findById(id);
        User user = byId.get();
        return user;
    }

    @Override
    public int deleteUser(Long[] ids) throws Exception {

        return 0;
    }

    @Override
    public List<User> list(User user) throws Exception {

        List<User> all = userDao.findAll();
        return all;
    }

    @Override
    public Page<User> page(User user) throws Exception {

        PageRequest page = new PageRequest(0, 10);
        Page<User> all = userDao.findAll(page);
        return all;
    }

    @Override
    public User save(User user) throws Exception {
        User save = userDao.save(user);
        return save;
    }
}
